package com.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.beans.ClassInfo;
import com.dao.ClassDao;

@Controller
@RequestMapping("/base")
public class ClassController {
	@Resource
	ClassDao classDao;
@RequestMapping("/classAdd")
public String addClass(ModelMap map,@ModelAttribute ("classInfo")ClassInfo classInfo) {
	classDao.save(classInfo);
	map.put("msg", "添加成功");
	return "/admin/base_info/class_add.jsp";
}
@RequestMapping("/classManager")
public String manageClass(ModelMap map) {
	map.put("classList", classDao.findAll());
	return "/admin/base_info/class_manager.jsp";
}

@RequestMapping("classDelete/{classId}")
public String deleteStudentById(@PathVariable("classId")Integer classId,ModelMap map) {
	classDao.deleteById(classId);
	map.put("classList",classDao.findAll());
	map.put("msg","删除成功");
	return "/admin/base_info/class_manager.jsp";
}
@RequestMapping("classUpdate/{classId}")
public String goUpdateStudentById(@PathVariable("classId")Integer classId,ModelMap map) {
	map.put("classInfo",classDao.getOne(classId));
	return "/admin/base_info/class_update.jsp";
}
@RequestMapping("classUpdate")
public String udateStudent(@ModelAttribute ("classInfo")ClassInfo classInfo,ModelMap map) {
	classDao.save(classInfo);
	map.put("msg","修改成功");
	return "/admin/base_info/class_update.jsp";
}
}
